(function(t){if(!!t.JCCatalogCompareList){return}t.JCCatalogCompareList=function(t){this.obCompare=null;this.obAdminPanel=null;this.visual=t.VISUAL;this.ajax=t.AJAX;this.position=t.POSITION;BX.ready(BX.proxy(this.init,this))};t.JCCatalogCompareList.prototype.init=function(){this.obCompare=BX(this.visual.ID);if(BX.type.isElementNode(this.obCompare)){BX.addCustomEvent(t,"OnCompareChange",BX.proxy(this.reload,this));BX.bindDelegate(this.obCompare,"click",{tagName:"a"},BX.proxy(this.deleteCompare,this));if(this.position.fixed&&this.position.align.vertical==="top"){this.obAdminPanel=BX("bx-panel");if(BX.type.isElementNode(this.obAdminPanel)){this.setVerticalAlign();BX.addCustomEvent(t,"onTopPanelCollapse",BX.proxy(this.setVerticalAlign,this))}}}};t.JCCatalogCompareList.prototype.reload=function(){BX.showWait(this.obCompare);BX.ajax.post(this.ajax.url,this.ajax.reload,BX.proxy(this.reloadResult,this))};t.JCCatalogCompareList.prototype.reloadResult=function(t){var e="none";BX.closeWait();this.obCompare.innerHTML=t;if(BX.type.isNotEmptyString(t)){if(t.indexOf("<table")>=0)e="block"}BX.style(this.obCompare,"display",e)};t.JCCatalogCompareList.prototype.deleteCompare=function(){var t=BX.proxy_context,e,i;if(!!t&&t.hasAttribute("data-id")){e=parseInt(t.getAttribute("data-id"),10);if(!isNaN(e)){BX.showWait(this.obCompare);i=this.ajax.url+this.ajax.templates.delete+e.toString();BX.ajax.loadJSON(i,this.ajax.params,BX.proxy(this.deleteCompareResult,this))}}};t.JCCatalogCompareList.prototype.deleteCompareResult=function(t){var e,i,o,a;BX.closeWait();if(BX.type.isPlainObject(t)){if(BX.type.isNotEmptyString(t.STATUS)&&t.STATUS==="OK"&&!!t.ID){BX.onCustomEvent("onCatalogDeleteCompare",[t.ID]);e=this.obCompare.querySelector('table[data-block="item-list"]');if(BX.type.isElementNode(e)){if(e.rows.length>1){for(i=0;i<e.rows.length;i++){if(e.rows[i].hasAttribute("data-row-id")&&e.rows[i].getAttribute("data-row-id")==="row"+t.ID){e.deleteRow(i)}}if(BX.type.isNotEmptyString(t.COUNT)||BX.type.isNumber(t.COUNT)){a=parseInt(t.COUNT,10);if(!isNaN(a)){o=this.obCompare.querySelector('span[data-block="count"]');if(BX.type.isElementNode(o)){o.innerHTML=a.toString()}o=null;BX.style(this.obCompare,"display",a>0?"block":"none")}}}else{this.reload()}}e=null}}};t.JCCatalogCompareList.prototype.setVerticalAlign=function(){var t;if(BX.type.isElementNode(this.obCompare)&&BX.type.isElementNode(this.obAdminPanel)){t=parseInt(this.obAdminPanel.offsetHeight,10);if(isNaN(t)){t=0}t+=5;BX.style(this.obCompare,"top",t.toString()+"px")}}})(window);